﻿<?php
function showtable($ref, $ciucourses, $owncourses, $states){
?>

  <?php $tokens=array( 0=> "", 1=>"Cursos Disponibles" )  ?>
  <?php  echo $ref->element("breadcrumb", array('tokens'=>$tokens) ); ?>
  <table class="zebra" cellpadding="0" cellspacing="0">
  <thead>
  <tr>
      <th><?php echo $ref->Paginator->sort('id');?></th>
      <th><?php echo $ref->Paginator->sort('ciulanguage_id');?></th>
      <th><?php echo $ref->Paginator->sort('ciutimetable_id');?></th>
      <th><?php echo $ref->Paginator->sort('ciuroom_id');?></th>
      <th><?php echo $ref->Paginator->sort('Preinscrito');?></th>
	  <th><?php echo $ref->Paginator->sort('Cupos' );?></th>
     <th class="actions"><?php __('Actions');?></th>
  </tr>
  </thead>
  <tbody>
  <?php
  $i = 0;
  
  foreach ($ciucourses as $ciucourse):
    $class = null;
    if ($i++ % 2 == 0) {
      $class = ' class="altrow"';
    }
  ?>
  <tr<?php echo $class;?>>
    <td><?php echo $ciucourse['Ciucourse']['id']; ?>&nbsp;</td>
    <td>
      <?php echo $ciucourse['Ciusubject']['name']; ?>
    </td>
    <td>
      <?php echo $ciucourse['Ciutimetable']['name']; ?>
    </td>
    <td>
      <?php echo $ciucourse['Ciuroom']['name']; ?>
    </td>
    <td>
	  <?php if( in_array( $ciucourse['Ciucourse']['id'], array_keys($owncourses) )  ){  ?>
	  <?php  	//echo __( $states[ $owncourses[  $ciucourse['Ciucourse']['id'] ]] ) ; ?>
	  <?php     if(  $owncourses[  $ciucourse['Ciucourse']['id'] ] == 1){
					echo "Sí";
				}
	  ?>
      <?php }else{ ?>
				&nbsp;
	  <?php } ?>
	</td>
	<td>
	 <?php echo $ciucourse['Ciucourse']['capacity'] - $ciucourse['Ciucourse']['people_count']  ?>
	</td>
	
    <td class="actions">
      <?php echo $ref->Html->link(__('Preinscribir', true), array('action' => 'preregister', $ciucourse['Ciucourse']['id'])); ?>
    </td>
  </tr>
<?php endforeach; ?>
		</tbody>
  </table>
  
  <div class="paginatorcounter">
  <?php
  echo $ref->Paginator->counter(array(
  'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
  ));
  ?>  </div>

  <div class="paging">
    <?php echo $ref->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
   |  <?php echo $ref->Paginator->numbers();?>|
    <?php echo $ref->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
  </div>
<?php } ?>  



<div class="ciucourses contenidofijo">
  <?php //if (strtotime(date($startDate)) <= time() and strtotime(date($endDate)) >= time()) {?>
  <?php if(true){ ?> 
  <?php
		if(empty($posibles)){
			echo $this->element('showmsg',array('msg'=>'No se han abierto cursos para su nivel.'));
		}else{
			if( empty($ciucourses) ){
				echo $this->element('showmsg',array('msg'=>'No se encuentran cursos disponibles para ud. por el momento.'));
			}else{
				showtable($this, $ciucourses, $owncourses, $states);
			}
		}	
	} else { ?>
        </br>
        <table>
            <tr>
                <td><?php echo $this->Html->image("bloqueado.jpg"); ?></td>
                <td></br></br></br></br></br></br>
                    <h2>Esta opción se encuentra deshabilidata.
                    </h2>
                    <h2>Recuerde solo se podrá preinscribir a cursos desde el 
                        <strong><?php echo $startDate ?></strong> 
                        hasta 
                        <strong><?php echo $endDate ?></strong>. 
                    </h2></td>
            </tr>
        </table>
	<?php } ?>
</div>